package com.bite.system.Controller;

import Constants.JwtConstants;
import com.bite.system.Service.SysUserService;
import com.bite.system.VO.SysUserVO;
import com.bite.system.DTO.SysUserDTO;
import domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "系统用户")
@Slf4j
//系统用户模块
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @PostMapping("/login")
    @Operation(summary = "登录", description = "系统用户登录接口")
    @ApiResponse(responseCode = "200", description = "登录成功")
    @ApiResponse(responseCode = "400", description = "登录失败")
    @ApiResponse(responseCode = "500", description = "服务器内部错误")
    @Parameters({
            @Parameter(name = "sysUserDTO", description = "系统用户登录信息", required = true),
    })
    public R<Object> login(@Validated @RequestBody SysUserDTO sysUserDTO){

        log.info("用户登录信息：{}", sysUserDTO);
        return sysUserService.login(sysUserDTO);
    }


    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(JwtConstants.TOKEN) String token){
        return sysUserService.logout(token);
    }


    @GetMapping("/info")
    public R<SysUserVO> info(){
        return sysUserService.info();
    }





    @GetMapping("/text")
    public R<Object> text(){
        return R.success("测试成功");
    }



}
